﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using BusinessTier.Facade.Interface;
using BusinessTier.Facade.Implementation;
using WebMVC.Models;

namespace WebMVC.Controllers
{
    [HandleError]
    public class HomeController : ControllerBase
    {
        private INewsService newsService;

        public HomeController() : this(new NewsService())
        {
            
        }

        public HomeController(INewsService newsService)
        {
            this.newsService = newsService;
        }

        //[OutputCache(Duration = int.MaxValue, VaryByParam = "none")]
        public ActionResult Index()
        {
            return View();
        }

        //[OutputCache(Duration = int.MaxValue, VaryByParam = "none")]
        public ActionResult About()
        {
            return View();
        }

        //[OutputCache(Duration = int.MaxValue, VaryByParam = "none")]
        public ActionResult Printing()
        {
            return View();
        }

        [OutputCache(Duration = int.MaxValue, VaryByParam = "none")]
        public ActionResult Underconstruction()
        {
            return View();
        }

        //[OutputCache(Duration = int.MaxValue, VaryByParam = "none")]
        public ActionResult ContactUs()
        {
            return View();
        }

        public ActionResult NewsNavControl()
        {
            var model = new List<NewsItemViewModel>();
            var newsItems = newsService.GetLastNewsItems(2, CurrentCulture.ToString());
            newsItems.ForEach(n => model.Add(new NewsItemViewModel{
                                ContentHTML = n.BodyHtml,
                                Date = n.CreateDate,
                                Id = n.NewsItemId,
                                Subject = n.Subject
            }));

            return PartialView(model);
        }

        public ActionResult SpecialOffersNavControl()
        {
            var model = new List<SpecialOfferViewModel>();
            var newsItems = newsService.GetLastSpecialOffers(2, CurrentCulture.ToString());
            newsItems.ForEach(n => model.Add(new SpecialOfferViewModel
            {
                ContentHTML = n.ContentHtml,
                CreateDate = n.CreateDate,
                Id = n.SpecialOfferId,
                Subject = n.Subject,
                StartDate = n.StartDate,
                EndDate = n.EndDate,
                EndDateString = n.EndDateString
            }));

            return PartialView(model);
        }
    }
}
